#pragma once
#include<iostream>
#include<pthread.h>
#include"Mutex.hpp"

using namespace MuteModule;

namespace CondModule
{
    class Cond
    {
    public:
        Cond()
        {
            int n = pthread_cond_init(&_cond,nullptr);
            if(n != 0)
            {
                std::cout << "pthread_cond_int error" << std::endl;
            }
        }
        void Wait(Mutex& mutex)
        {
            int n = pthread_cond_wait(&_cond,mutex.Get());
            if(n != 0)
            {
                std::cout << "pthread_cond_wait error" << std::endl;
            }
        }
        void Signal()
        {
            int n = pthread_cond_signal(&_cond);
            if(n != 0)
            {
                std::cout << "pthread_cond_signal error" << std::endl;
            }
        }
        void Broadcast()
        {
            int n = pthread_cond_broadcast(&_cond);
            if(n != 0)
            {
                std::cout << "pthread_cond_broadcast error" << std::endl;
            }
        }
        ~Cond()
        {
            int n = pthread_cond_destroy(&_cond);
            if(n != 0)
            {
                std::cout << "pthread_cond_destroy error" << std::endl;
            }
        }
    private:
        pthread_cond_t _cond;
    };
}